from django.core.exceptions import ValidationError

def validate_facts_and_recs(word):
    if(word.find(" ") >= 0):
        raise ValidationError(u'space not allowed. use _ instead')
    
def validate_when(fact1, fact2, fact3, logical_operator1, logical_operator2):
    if(fact2 == None and (not logical_operator1 == None)):
       raise ValidationError(u'fact2 missing')
   
    if((not fact2 == None) and logical_operator1 == None):
       raise ValidationError(u'logical_operator1 missing')
    
    if(fact3 == None and (not logical_operator2 == None)):
       raise ValidationError(u'fact3 missing')
            
    if((not fact3 == None) and logical_operator2 == None):
       raise ValidationError(u'logical_operator2 missing')
   
    if((not fact3 == None) and fact2 == None):
       raise ValidationError(u'fact2 missing')
   
    if((not logical_operator2 == None) and logical_operator1 == None):
       raise ValidationError(u'logical_operator1 missing')
   
def validate_rule(rec1, rec2):
    if(rec1 == None and (not rec2 == None)):
       raise ValidationError(u'rec1 missing')
   
def validate_QuestionSet(name, question_sets_for_questions, question_sets_for_question_sets):
    if(len(question_sets_for_questions) > 0 and len(question_sets_for_question_sets) > 0):
        raise ValidationError(u'question_sets cannot have both types. Empty either one of question_sets_for_questions or question_sets_for_question_sets')
    
    for question_set_for_question_sets in question_sets_for_question_sets:
        if(question_set_for_question_sets.name == name):
            raise ValidationError(u'question_sets_for_questions is containing itself.')